import requests
import json

GOOGLE_TR_CODE = ["en","ja","ko","ar","th","ru","zh-TW","id","de","vi","el","hu","hi","id","it","fr","es","nl","pl","pt","ro","ru","ar","zh-TW","ko","sv","th","tr","vi"]


print('开始。。。。')

with open("zh.json",'r') as load_f:
    json_dict = json.load(load_f)
    json_keylist = list(json_dict.keys())
    #print(load_dict)
    
    counter = 0
    while counter < len(json_keylist):
        print(json_dict[json_keylist[counter]])
        response = requests.get('https://translation.googleapis.com/language/translate/v2', params={'key': 'AIzaSyBtiAkwH7g3kr12aSdzCagOgzozD0N9G_A', 'source': 'zh-CN', 'target': 'en', 'q': json_dict[json_keylist[counter]]})

        json_str = json.dumps(response.json())
        googleapi_return = json.loads(json_str)
        #print(json_str)
        tr_str = googleapi_return['data']['translations'][0]['translatedText']

        json_dict[json_keylist[counter]] = tr_str.replace('&#39;','‘').capitalize()
        print(tr_str)
        print("-------------------------------\n")
        counter += 1
    with open("en.json","w+") as dump_f:
        json.dump(json_dict,dump_f,ensure_ascii=False,indent=2)

    print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')

